﻿var main = {
	init : function(){
		var boss = this;
		
		boss.initLayout();
		boss.initEvent();
		zonggai.init();
	},
	initLayout : function(){
		var boss = this;

		boss.reSize(false, false);
		$("div[under], div[tag='z2'], div[tag='z3'], div[tag='z4']").hide();
		$("#main div[tag]").hide();
		if(!(boss.getQueryString("tab")) || boss.getQueryString("tab") != ""){
			$("div[tag='zonggai']").show();
			boss.loadJsp("zonggai");
		} else {
			$("div[tag='" + boss.getQueryString("tab") + "']").show();
			boss.loadJsp(boss.getQueryString("tab"));
		}
	},
	initEvent : function(){
		var boss = this;
		
		orgSelecter.initOrgSelecter(boss.loadPoliceData,boss, boss.getQueryString("fullid"));
		boss.initTabEvent();
		$("#into_back").bind("click", function(){
			$(this).attr("href", burl + "/view/manager/main.jsp?action=/view/manager/Statistics.jsp");
		});
		$("#exit_session").bind("click", function(){
			sbl.ajax({
				url: burl + "/User/Exsit.do",
				data: {},
				success: function(d){
					alert(d.msg);
					window.location.href = burl + "/view/login.jsp";
				}
			});
		});
	},
	loadPoliceData : function(){
		var tag = $("#tab li[class='selected']").attr("tag");
		if(tag == "zonggai"){
			zonggai.initText();
			zonggai.initEvent();
		}else if(tag == "grid"){
			grid.MenuTab();
			grid.initGridConditions();
		}
	},
	initTabEvent : function(){
		var boss = this;
		$("#tab li").bind("click", function(){
			var tag = $(this).attr("tag");
			$("#tab li").removeClass("selected");
			$(this).addClass("selected");
			$("#main div[tag]").hide();
			$("div[tag='" + tag + "']").show();
			boss.loadJsp(tag);
		});
	},
	reSize : function(isHideFilter,isHideTop){
		var mainWidth = 0;
		var mainHeight = 0;
		var bodyWidth = document.documentElement.clientWidth;
		var bodyHeight = document.documentElement.clientHeight;
		if(isHideTop){
			mainWidth = bodyWidth;
			mainHeight = bodyHeight;
			$("#header").hide();
		} else {
			mainWidth = bodyWidth;
			mainHeight = bodyHeight - $("#header").outerHeight();
			$("#header").show();
		}
		$("#main").css("width", mainWidth);
		$("#main").css("height", mainHeight);
	},
	loadJsp : function(tag){
		var boss = this;
		
		var htmlIndex = "";
	
		$("#tab li").removeClass("selected");
		$("#tab li[tag='" + tag + "']").addClass("selected");
		if(tag == "zonggai"){
			$.ajax({
				dataType : 'text',
				async : false,
				url : burl + "/view/main/zonggai.jsp",
				success : function(d) {
					htmlIndex = d;
				}
			});
			$("div[tag='" + tag + "']").html(htmlIndex);
			boss.initZonggaiSize();
			zonggai.init();
		} else if(tag == "grid"){
			$.ajax({
				dataType : 'text',
				async : false,
				url : burl + "/view/main/grid.jsp",
				success : function(d) {
					htmlIndex = d;
				}
			});
			$("div[tag='" + tag + "']").html(htmlIndex);
			boss.initGridSize();
			grid.init();
		} else if(tag == "map"){
			var fullid = $("#xuanxiangka div[tag^='z'][selected]").last().attr("fullid");
			window.location.href = burl + "/view/main/map.jsp?fullid=" + fullid;
		}
	},
	initZonggaiSize : function(){
		var textMainWidth = $("#main").outerWidth();
		var textMainHeight = $("#main").outerHeight();
		$("#zonggai_main").css("width", textMainWidth);
		$("#zonggai_main").css("height", textMainHeight-1);
		$("#wenzi").css("width", textMainWidth);
		$("#wenzi").css("height", textMainHeight-1);
	},
	initGridSize : function(){
		var gridMainWidth = $("#main").outerWidth();
		var gridMainHeight = $("#main").outerHeight();
		var gridWidth = gridMainWidth - $("#menu_tab").innerWidth();
		var gridPanelHeight = gridMainHeight - $(".condition-tab").innerHeight();
		var gridHeight = gridMainHeight;
		$("#grid_main").css("width", gridWidth-1);
		$("#grid_main").css("height", gridHeight);
		$("#menu_tab").css("height", gridMainHeight);
		$("#menu_tab div[tag]").css("height", gridPanelHeight);
	},
	getQueryString : function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
    }
};
$(function(){
	main.init(); 
});